local WEED_DEFS                 = require("prefabs/weed_defs").WEED_DEFS
local my_plant_table            = { "weed_daogui_ganoderma", "weed_daogui_ginseng" }

local DAYS                      = TUNING.TOTAL_DAY_TIME -- 一天,8分钟

WEED_DEFS.weed_daogui_ganoderma = { build = "weed_daogui_ganoderma", bank = "weed_daogui_ganoderma" }
WEED_DEFS.weed_daogui_ginseng   = { build = "weed_daogui_ginseng", bank = "weed_daogui_ginseng" }

local function MakeGrowTimes(full_grow_min, full_grow_max, bolting)
    local grow_time = {}

    -- 生长时间
    if bolting then
        grow_time.small = { full_grow_min * 0.3, full_grow_max * 0.3 }
        grow_time.med   = { full_grow_min * 0.3, full_grow_max * 0.3 }
        grow_time.full  = { full_grow_min * 0.4, full_grow_max * 0.4 }
    else
        grow_time.small = { full_grow_min * 0.6, full_grow_max * 0.6 }
        grow_time.med   = { full_grow_min * 0.4, full_grow_max * 0.4 }
    end

    return grow_time
end

-- 生长阶段之间,最大最小生长时间
WEED_DEFS.weed_daogui_ganoderma.grow_time            = MakeGrowTimes(2 * DAYS, 3 * DAYS, false)
WEED_DEFS.weed_daogui_ginseng.grow_time              = MakeGrowTimes(2 * DAYS, 3 * DAYS, false)

-- 至成熟阶段时间
WEED_DEFS.weed_daogui_ganoderma.spread               = { stage = "full", time_min = 6.0 * DAYS, time_var = 2.0 * DAYS, tilled_dist = 10, ground_dist = 5, ground_dist_var = 5, tooclose_dist = 5 }
WEED_DEFS.weed_daogui_ginseng.spread                 = { stage = "full", time_min = 6.0 * DAYS, time_var = 2.0 * DAYS, tilled_dist = 10, ground_dist = 5, ground_dist_var = 5, tooclose_dist = 5 }

-- 种子概率
-- WEED_DEFS.weed_daogui_ganoderma.seed_weight          = TUNING.SEED_CHANCE_RARE

-- 产物
WEED_DEFS.weed_daogui_ganoderma.product              = "daogui_ganoderma"
WEED_DEFS.weed_daogui_ginseng.product                = "daogui_ginseng"

-- 消耗养分
local nutrient                                       = TUNING.FARM_PLANT_CONSUME_NUTRIENT_LOW
WEED_DEFS.weed_daogui_ganoderma.nutrient_consumption = { nutrient, nutrient, nutrient }
WEED_DEFS.weed_daogui_ginseng.nutrient_consumption   = { nutrient, nutrient, nutrient }

-- 消耗水分
local drink_low                                      = TUNING.FARM_PLANT_DRINK_LOW
local drink_med                                      = TUNING.FARM_PLANT_DRINK_MED
WEED_DEFS.weed_daogui_ganoderma.moisture             = { drink_rate = drink_med }
WEED_DEFS.weed_daogui_ginseng.moisture               = { drink_rate = drink_low }

for weed, data in pairs(WEED_DEFS) do
    local my_plant = table.contains(my_plant_table, weed)
    if my_plant then
        data.prefab = weed
        data.sameweedtags = { weed }

        if data.stage_netvar == nil then
            data.stage_netvar = net_tinybyte
        end

        if data.plantregistryinfo == nil then
            data.plantregistryinfo = {
                {
                    text = "small",
                    anim = "crop_small",
                    grow_anim = "seedless_to_small",
                    growing = true,
                },
                {
                    text = "medium",
                    anim = "crop_med",
                    grow_anim = "grow_med",
                    growing = true,
                },
                {
                    text = "grown",
                    anim = "crop_full",
                    grow_anim = "grow_full",
                    revealplantname = true,
                    fullgrown = true,
                },
            }

            if data.grow_time.full then
                table.insert(data.plantregistryinfo, {
                    text = "bolting",
                    anim = "crop_bloomed",
                    grow_anim = "grow_bloomed",
                    revealplantname = true,
                    fullgrown = true,
                    stagepriority = -1,
                })
            end

            if data.product then
                table.insert(data.plantregistryinfo, {
                    text = "picked",
                    anim = "crop_picked",
                    grow_anim = "grow_picked",
                    stagepriority = -100
                })
            end
        end
        if data.plantregistrywidget == nil then
            -- 组件路径
            data.plantregistrywidget = "widgets/redux/weedplantpage"
        end
    end
end

local weighted_seed_table = require("prefabs/weed_defs").weighted_seed_table
for k, v in pairs(WEED_DEFS) do
    weighted_seed_table[k] = v.seed_weight
end
